<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>ESMS</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/ssm_esms/static/css/font.css">
    <link rel="stylesheet" href="/ssm_esms/static/css/xadmin.css">
    <script type="text/javascript" src="/ssm_esms/static/js/jquery-3.3.1.js"></script>
    <script type="text/javascript" src="/ssm_esms/static/lib/layui/layui.js"></script>
    <script type="text/javascript" src="/ssm_esms/static/js/xadmin.js"></script>

</head>

<body class="layui-anim layui-anim-up">

<div class="x-nav">
      <span class="layui-breadcrumb">
        <a>首页</a>
        <a>岗位管理</a>
        <a>
          <cite>岗位列表</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body" id="container">
    <div class="layui-row">
        <div class="demoTable layui-col-md11 layui-form">
            岗位名称：
            <div class="layui-inline">
                <input class="layui-input" name="id" id="demoReload" autocomplete="off">
            </div>
            <button class="layui-btn" data-type="reload">搜索</button>
        </div>
        <!--<xblock>-->
        <!--<button class="layui-btn" onclick="x_admin_show('添加','toPage.do?url=admin/position-add.html',600,400)"><i class="layui-icon"></i>添加</button>-->
        <!--</xblock>-->
        <div class="layui-col-md1">
            <div class="layui-inline">
                <button class="layui-btn" style=" margin-top: 0px;padding: 2px 10px 4px 10px"
                        onclick="x_admin_show('添加','toPage.do?url=admin/position-add.html',600,400)"><i
                        class="layui-icon"></i>添加
                </button>
            </div>
        </div>
    </div>


    <div style="text-align: center">
        <table class="layui-table"
               lay-data="{height: 'full-160', cellMinWidth:80, url:'position/findSelective.do', page:true, id:'idTest'}"
               lay-filter="demo">
            <thead>
            <tr>
                <th lay-data="{field:'pName', width:200, fixed: true,align: 'center'}">岗位名称</th>
                <th lay-data="{field:'pDuty', minWidth:400,align: 'center'}">岗位描述</th>
                <th lay-data="{field:'pPostPay', width:200,align: 'center'}">岗位补贴</th>
                <th lay-data="{fixed: 'right', width:195, align:'center', toolbar: '#barDemo'}"></th>
            </tr>
            </thead>
        </table>
    </div>

</div>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    layui.use('table', function () {
        var table = layui.table;

        //监听工具条
        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.msg('ID：' + data.id + ' 的查看操作');
            } else if (obj.event === 'del') {
                layer.confirm('确定要删除吗', function (index) {
                    // console.log(data);
                    $.ajax({
                        type: 'post',
                        url: 'position/deleteByPrimaryKey.do',
                        data: {"id": data.pId},
                        dataType: 'json',
                        success: function (data) {
                            //alert(data);
                            if (data == 1) {
                                layer.msg('已删除!', {icon: 1, time: 4000});
                                // $(obj).parents("tr").remove();
                                obj.del();

                            }
                            else {
                                //alert("exist");
                                layer.msg('删除失败!', {icon: 5, time: 1000});
                            }
                        },
                        error: function (data) {
                            // alert("error" + data);
                            layer.alert("抱歉！出现未知错误！", {icon: 5});
                        }
                    });
                    // layer.close(index);
                    // location.reload();
                });
            } else if (obj.event === 'edit') {
                // layer.alert('编辑行：<br>'+ JSON.stringify(data));
                x_admin_show('编辑', 'toPage.do?url=admin/position-edit.html?pId=' + data.pId + '&pName=' + data.pName + '&pDuty=' + data.pDuty + '&pPostPay=' + data.pPostPay, 600, 400);

            }
        });

        var $ = layui.$, active = {

            reload: function () {
                var demoReload = $('#demoReload');
                // alert("asd");
                //执行重载
                table.reload('idTest', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        p_name: demoReload.val()
                    }
                });
            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


    });

</script>

</body>

</html>